package valid_contr
{
	import mx.controls.DataGrid;
	
	public class nsdatagrid extends DataGrid
	{
		protected namespace ns = "http://soap.sforce.com/2006/04/metadata";
		
		public function nsdatagrid()
		{
			super();
		}
		
		//default implementations of these two methods, intended for subclassing
		//not checking if it really is a complex value here as the performance hit of doing this here is negligible
		//compared with every display
		override protected function getCurrentDataValue( data:Object, property:String ):String
		{
			use namespace ns;
			// use namespace does not reach into a call to super so copied parents code
			if ( !isComplexColumn( property ) )
				return data[ property ];
			
			var complexFieldNameComponents:Array = property.split( "." );
			var obj:Object = deriveComplexFieldReference( data, complexFieldNameComponents );
			
			return String( obj );
		}
		
		//Passing all of these parameters as it basically allows everything you would need to subclass for all sorts of fun implementations
		override protected function setNewValue( data:Object, property:String, value:Object, columnIndex:int ):Boolean
		{
			use namespace ns;
			// use namespace does not reach into a call to super so copied parents code
			if ( !isComplexColumn( property ) )
			{
				data[ property ] = value;
			}
			else
			{
				var complexFieldNameComponents:Array = property.split( "." );
				var lastProp:String = complexFieldNameComponents.pop();
				var parent:Object = deriveComplexFieldReference( data, complexFieldNameComponents );
				parent[ lastProp ] = value;
			}
			
			//The value they typed in is always converted to a string, but is the value actually a string in the dataprovider?
			//unknown as it is cast by datagridcolumn before datagrid ever gets to know...
			//control if this really causes an update in subclass
			return true;
		}
	}
}
